import request from '@/utils/request'

// ==================== 面试预约管理相关API ====================

// 获取学生的面试预约 (学生专用接口)
export function getStudentAppointments(studentId) {
  // 添加fallback机制
  if (!studentId || studentId === 'undefined' || studentId === 'null' || studentId === '') {
    studentId = localStorage.getItem('userId') || '1'
    console.log('Fallback to localStorage userId:', studentId)
  }
  return request({
    url: '/campus/student/' + studentId + '/appointments',
    method: 'get'
  })
}

// 查询面试时段列表 (管理员接口，学生不应直接调用)
export function listInterviewSlot(query) {
  return request({
    url: '/campus/interviewSlot/list',
    method: 'get',
    params: query
  })
}

// 查询面试预约列表 (管理员接口，学生不应直接调用)
export function listInterviewAppointment(query) {
  return request({
    url: '/campus/interviewAppointment/list',
    method: 'get',
    params: query
  })
}

// 新增面试预约
export function addInterviewAppointment(data) {
  return request({
    url: '/campus/interviewAppointment',
    method: 'post',
    data: data
  })
}

// 修改面试预约
export function updateInterviewAppointment(data) {
  return request({
    url: '/campus/interviewAppointment',
    method: 'put',
    data: data
  })
}

// 学生预约面试
export function bookInterview(data) {
  return request({
    url: '/campus/interviewAppointment/book',
    method: 'post',
    data: data
  })
}

// 取消预约
export function cancelAppointment(appointmentId) {
  return request({
    url: '/campus/interviewAppointment/cancel/' + appointmentId,
    method: 'put'
  })
}

// 添加默认导出以确保模块正确导入
export default {
  getStudentAppointments,
  listInterviewSlot,
  listInterviewAppointment,
  addInterviewAppointment,
  updateInterviewAppointment,
  bookInterview,
  cancelAppointment
}